Subject: Re: Using Message Ports in C, and in Pascal...
From: [email-masked] (Olaf Seibert)
Date: Tue, 8 Mar 1994 10:39:04 GMT
Newsgroups: comp.sys.amiga.programmer

In <[email-masked]> [email-masked] (Peter Simons) writes:
>The reason is that PutMsg() and other routines exptect a pointer to a
>'Message' structure as parameter, which is just the node header to
>chain them in a list, a pointer to the reply port and the length of
>the message. Obviously, the length specifies how many byte of actual
>data are appended. Now, most programmer define their own structure
>which is a usual 'Message' plus the to-be-sent data and send this
>structure off.
>
>You do not really need to typecast the structure, but otherwise your
>compiler would complain because he expects a pointer to 'Message' and
>not to 'whateverMessage'. In fact, it doesn't make a difference for
>the routine it's just common practise to cast in such situations.

In fact, there is a slightly different solution, that is on average
about the same amount of typing, but somewhat cleaner.

Suppose you have

struct MyMsg {
	struct Message msg;
	int data;
} *mymsg;

and you want to PutMsg() it. Now you could do

	PutMsg((struct Message *)mymsg, ...);

but also

	PutMsg(&mymsg->msg, ...);

This lets the compiler check the types better, because there is no
cast. This solution works for almost all AmigaOS structures; the
most annoying ones that don't work are MinList vs. List and MinNode
vs. Node. These are interchangable for most List manipulating functions,
yet the types are different.

>        bye, Peter
-Olaf.
--
___ Olaf 'Rhialto' Seibert      D787B44DFC896063 4CBB95A5BD1DAA96 
\X/ There are no lemurs in this post    [email-masked]